package org.jeecg.trace.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.trace.entity.MesLotStatus;
import org.jeecg.trace.mapper.MesLotStatusMapper;
import org.jeecg.trace.mapper.MesPackItemMapper;
import org.jeecg.trace.service.IMesLotStatusService;
import org.jeecg.common.api.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description: 产品批次表
 * @Author: shaolong
 * @Date: 2022-11-16
 * @Version: V1.0
 */
@Service
public class MesLotStatusServiceImpl extends ServiceImpl<MesLotStatusMapper, MesLotStatus> implements IMesLotStatusService {

	@Autowired
	private MesLotStatusMapper mesLotStatusMapper;
	@Autowired
	private MesPackItemMapper mesPackItemMapper;


	@Override
	@Transactional(rollbackFor = Exception.class)
	public void delMain(String id) {
		mesPackItemMapper.deleteByMainId(id);
		//把这里的删除给改了 改成按照id删
		Map<String, Object> map = new HashMap<>();
		map.put("REC_ID", id);
		mesLotStatusMapper.deleteByMap(map);
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void delBatchMain(Collection<? extends Serializable> idList) {
		for (Serializable id : idList) {
			mesPackItemMapper.deleteByMainId(id.toString());
			mesLotStatusMapper.deleteById(id);
		}
	}

	@Override
	public Result<String> edit(MesLotStatus mesLotStatus) {
		LambdaUpdateWrapper<MesLotStatus> eq = new LambdaUpdateWrapper<MesLotStatus>();
		//自定义更新条件   .eq(MesLineCfg::getLine, mesLineCfg.getLine());
		boolean update = update(mesLotStatus, eq);
		return update ? Result.ok("修改成功!") : Result.error("修改失败!");
	}

	@Override
	public IPage<MesLotStatus> pageList(Page<MesLotStatus> page, MesLotStatus mesLotStatus) {
		return mesLotStatusMapper.pageList(page,mesLotStatus);
	}
}
